#pragma once

#include "toolTypes.h"
#include <string>
using std::string;

//class CSimpleScene;
class TiXmlElement;
class CMaterial;
class CNodeCSG;
class IPrimitive;

class CSceneLoader
{
private:
	string m_filename;
	//CSimpleScene* m_scene;

public:
	CSceneLoader();
	bool load(const string& filename);

	IPrimitive* loadModelFile(const string& filename)const;
private:
	void loadConfiguration(TiXmlElement* config)const;
	void loadScene(TiXmlElement* scene)const;
	void loadLights(TiXmlElement* light)const;
	void loadMaterials(TiXmlElement* material)const;
	void loadObjects(TiXmlElement* object)const;
	

	void loadGeometryCamera(TiXmlElement* element)const;
	IPrimitive* loadGeometryPlan(TiXmlElement* element)const;
	IPrimitive* loadGeometrySphere(TiXmlElement* element)const;
	IPrimitive* loadGeometryCylinder(TiXmlElement* element)const;
	IPrimitive* loadGeometryCone(TiXmlElement* element)const;
	IPrimitive* loadGeometryTorus(TiXmlElement* element)const;
	IPrimitive* loadGeometryTriangle(TiXmlElement* element)const;
	IPrimitive* loadGeometryBox(TiXmlElement* element)const;
	IPrimitive* loadGeometryCSG(TiXmlElement* element)const;
	CNodeCSG* loadNodeCSG(TiXmlElement* element)const;
	IPrimitive* loadGeometryFromFile(TiXmlElement* element)const;

	void loadTransformRotation(TiXmlElement* element, CMatrix& out)const;
	void loadTransformTranslate(TiXmlElement* element, CMatrix& out)const;
	void loadTransformScale(TiXmlElement* element, CMatrix& out)const;

	void loadProcTextureChecker(TiXmlElement* element, CMaterial* material)const;
	void loadProcTextureWood(TiXmlElement* element, CMaterial* material)const;
	void loadProcTextureMarble(TiXmlElement* element, CMaterial* material)const;
	void loadProcTextureThreshold(TiXmlElement* element, CMaterial* material)const;
	void loadProcTextureBump(TiXmlElement* element, CMaterial* material)const;


	void getVector3(TiXmlElement* position, CVector3f& vector3)const;
	float getFloat(TiXmlElement* element)const;
};